package com.mls.fivedistrict.controller.backend;

import com.github.pagehelper.PageInfo;
import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.controller.BaseController;
import com.mls.fivedistrict.pojo.Calculate;
import com.mls.fivedistrict.server.CalculateService;
import com.mls.fivedistrict.server.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by chenxiuxiang on 2018/3/19.
 */
@RestController
@RequestMapping("/api/manager")
public class CalculateController extends BaseController {
    @Resource(name = "calculateService")
    CalculateService calculateService;
    @Resource(name = "userService")
    UserService userService;

    @PutMapping("/v1/calculate/{userId}")
    public ServiceResponse addCalculate(@PathVariable("userId") Long userId, @RequestBody Calculate calculate) {
        return userService.addCalculate(calculate, userId);
    }

    @RequestMapping("/v1/calculates/{userId}")
    public ServiceResponse getCalculateByUserId(@PathVariable("userId") Long userId) {
        List<Calculate> calculateList = calculateService.getCalculateByUserId(userId, getPageFilter());
        PageInfo pageInfo = new PageInfo(calculateList);
        return ServiceResponse.createSuccessResponse(pageInfo);
    }

}

